// axios基础封装
import axios from 'axios'

const httpInstance = axios.create({
  baseURL: 'http://pcapi-xiaotuxian-front-devtest.itheima.net',
  timeout: 5000
})

// 拦截器

httpInstance.interceptors.request.use(config => {
  // 拦截到请求，请求头携带token
  const token = 'token'
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  // console.log('请求成功')
  return config
}, err => {
  // console.log('请求失败')
  return err
})

httpInstance.interceptors.response.use(res => {
  // console.log('响应成功')
  return res.data
}, err => {
  // console.log('响应失败')
  return err
})

export default httpInstance
